#pragma once
#include "sgobject.h"
#include <vector>
#include "graphics/GrVector.h"

class CSgMesh :
	public CSgObject
{
public:
	CSgMesh(void);
	virtual ~CSgMesh(void);
	
	void AddVertex(const CGrVector &v) {m_vertices.push_back(v);}
    void AddNormal(const CGrVector &n) {m_normals.push_back(n);}
    void AddTexCoord(const CGrVector &t) {m_tvertices.push_back(t);}
	void AddTriangleVertex(int v, int n, int t);
	void AddFlatQuad(int a, int b, int c, int d, int n);

	// t1,t2,t3,t4 are the texture coordinates of quadrangle ABCD
	void AddFlatTexturedQuad(int a, int b, int c, int d, int n, CGrVector t1, CGrVector t2, CGrVector t3, CGrVector t4);
	void AddQuad(int a, int b, int c, int d);
	void Render(void);
	void ComputeSmoothNormals();
	void LoadOBJ(const char *filename);

private:
	std::vector<CGrVector> m_vertices;
    std::vector<CGrVector> m_normals;
    std::vector<CGrVector> m_tvertices;
	
	// A triangle vertex description
    struct TV
    {
        int     v;      // Vertex
        int     n;      // Normal
        int     t;      // Texture coordinate
    };

    typedef std::vector<TV> Triangles;
    typedef Triangles::iterator PTV;
    Triangles       m_triangles;
};
